package com.hopu.mapper;

import com.hopu.entity.Interaction;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface interactionMapper {

    /**
     * 查询用户视频关系表
     * @param userId
     * @param workId
     */
    @Select("select * from video.interaction where user_id=#{userId,} and work_id=#{workId};")
    Interaction getByUserIdAndInteractionId(Integer userId, Integer workId);

    /**
     * 插入用户与视频对应数据
     * @param interaction
     */
    @Insert("insert into video.interaction (user_id, work_id,like_status,collect_status) values " +
            "(#{userId},#{workId},#{likeStatus},#{collectStatus})")
    void insert(Interaction interaction);

    /**
     * 切换点赞状态
     * @param interaction
     */
    @Update("update video.interaction set like_status=#{likeStatus} where interaction_id=#{interactionId}")
    void updateLikeStatus(Interaction interaction);

    /**
     * 切换收藏状态
     * @param interaction
     */
    @Update("update video.interaction set collect_status=#{collectStatus} where interaction_id=#{interactionId}")
    void updateCollectStatus(Interaction interaction);
}
